<?php

if (!defined('BASEPATH'))
    exit('Tidak Diperkenankan mengakses langsung');
/* Class  Control : customer  * di Buat oleh Diar PHP Generator  *  By Diar */

class ctrviewcustomer extends CI_Controller {

    function __construct() {
        parent::__construct();
    }

    function index($xAwal = 0, $xSearch = '') {
       //$this->load->view('index_aca',$data);
        
       // $data['content'] = $this->createformcustomer('0', $xAwal);
        $this->load->view('index_aca');        
    }

//    function createformcustomer() {
//        $this->load->helper('form');
//        $this->load->helper('html');
//        $this->load->model('modelgetmenu');
//        $xAddJs = '<script language="javascript" type="text/javascript" src="' . base_url() . 'resource/ajax/baseurl.js"></script>' .
//                '<script language="javascript" type="text/javascript" src="' . base_url() . 'resource/ajax/ajaxviewcustomer.js"></script>';
//        echo $this->setDetailFormcustomer();
//    }

    function setDetailFormcustomer() {
        $this->load->helper('form');
        $xBufResult = '';
        $xBufResult = '<div id="stylized" class="myform">' . form_open_multipart('ctrcustomer/inserttable', array('id' => 'form', 'name' => 'form'));
        $this->load->helper('common');
        $xBufResult .= '<input type="hidden" name="edidx" id="edidx" value="0" />';
        $this->load->model('modelcountry');



//        $xBufResult .= '<div id="tabs">
//                                 <ul>
//                                   <li><a href="#dataumum"><span>Name And Address</span></a></li>
//                                   <li><a href="#dataumum2"><span>Postal Adress</span></a></li>
//                                   <li><a href="#dataumum3"><span>User And Password</span></a></li>
//                                   
//                                  </ul>';
      //  $xBufResult .= '<div id="dataumum">';
        $xBufResult .= '<style>label {width:20%;float:left;}';
        $xBufResult .= '</style>';
        
        $xBufResult .= setForm('edtitle', 'Title Mr,Mrs,Ir,Dr,Prof.', form_input(getArrayObj('edtitle', '', '50'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edfirstname', 'First Name', form_input(getArrayObj('edfirstname', '', '200')));
        $xBufResult .= setForm('edmidlename', 'Midle Name', form_input(getArrayObj('edmidlename', '', '200')));
        $xBufResult .= setForm('edlastname', 'Last Name', form_input(getArrayObj('edlastname', '', '200'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edorganization', 'Organization', form_input(getArrayObj('edorganization', '', '400'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edposition', 'Position', form_input(getArrayObj('edposition', '', '100'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edaddress', 'Address', form_textarea(getArrayObj('edaddress', '', '400'))) . '<div class="spacer"></div>';
   //     $xBufResult .= '</div><div id="dataumum2">';
        $xBufResult .= setForm('ediddepartemen', 'Country', form_dropdown('edidcountry', $this->modelcountry->getArrayListcountry(), '', ' id="edidcountry" onChange="dosetstate(\'0\');" class="require" style="width:200px;" ')) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edidstate', 'State', form_dropdown('edidstate', array(NULL), '', ' id="edidstate" onChange="dosetcity(\'0\');" class="require" style="width:200px;" ')) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edidcity', 'City', form_dropdown('edidcity', array(NULL), '', ' id="edidcity"  class="require" style="width:200px;" ')) . '<div class="spacer"></div>';
//         $xBufResult .= setForm('edidcountry', 'idcountry', form_input(getArrayObj('edidcountry', '', '100'))) . '<div class="spacer"></div>'; 
//         $xBufResult .= setForm('edidstate', 'idstate', form_input(getArrayObj('edidstate', '', '100'))) . '<div class="spacer"></div>';
//         $xBufResult .= setForm('edidcity', 'idcity', form_input(getArrayObj('edidcity', '', '100'))) . '<div class="spacer"></div>';


        $xBufResult .= setForm('edzipcode', 'Zip Code', form_input(getArrayObj('edzipcode', '', '200')));
        $xBufResult .= setForm('edtelepon', 'Telepon', form_input(getArrayObj('edtelepon', '', '200'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edmobile', 'Mobile', form_input(getArrayObj('edmobile', '', '200')));
        $xBufResult .= setForm('edfax', 'Fax', form_input(getArrayObj('edfax', '', '200'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edemail', 'Email', form_input(getArrayObj('edemail', '', '300'))) . '<div class="spacer"></div>';
     //   $xBufResult .= '</div><div id="dataumum3">';
        $xBufResult .= setForm('edusername', 'username', form_input(getArrayObj('edusername', '', '150'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edpassword', 'password', form_password(getArrayObj('edpassword', '', '150'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edcaptcha', 'Captcha', form_input(getArrayObj('edcaptcha', '', '100')),'1 + 3 =') . '<div class="spacer"></div>';
//        $xBufResult .= setForm('eddateentry', 'dateentry', form_input(getArrayObj('eddateentry', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edidpegawai', 'idpegawai', form_input(getArrayObj('edidpegawai', '', '100'))) . '<div class="spacer"></div>';
//        $xBufResult .= setForm('edstatus', 'status', form_input(getArrayObj('edstatus', '', '100'))) . '<div class="spacer"></div>';
       // $xBufResult .= setForm('edidcity', 'Status ', form_dropdown('edstatus', getstatusanggota(), '', ' id="edstatus"  class="require" style="width:200px;" ')) . '<div class="spacer"></div>';
//        $xBufResult .= '</div>';
        $xBufResult .= '<div class="garis"></div>' . form_button('btSimpan', 'Next >>', 'onclick="dosimpancustomer();" class="textbtn base_btn pull-left" style="margin-left:250px;"') . /*form_button('btNew', 'new', 'onclick="doClearcustomer();"') .*/ '<div class="spacer"></div>';
        return $xBufResult;
    }

    function getlistcustomer($xAwal, $xSearch) {
        $xLimit = 10;
        $this->load->helper('form');
        $this->load->helper('common');
        $xbufResult = tbaddrow(tbaddcell('idx', '', 'width=5%') .
                tbaddcell('Name', '', 'width=30%') .
                tbaddcell('organization', '', 'width=10%') .
                tbaddcell('position', '', 'width=10%') .
                tbaddcell('address', '', 'width=40%') .
                tbaddcell('Edit/Hapus', 'padding:5px;', 'width:10%;text-align:center;'), '', TRUE);
        $this->load->model('modelcustomer');
        $xQuery = $this->modelcustomer->getListcustomer($xAwal, $xLimit, $xSearch);
        foreach ($xQuery->result() as $row) {
            $xButtonEdit = '<img src="' . base_url() . 'resource/imgbtn/edit.png" alt="Edit Data" onclick = "doeditcustomer(\'' . $row->idx . '\');" style="border:none;width:20px"/>';
            $xButtonHapus = '<img src="' . base_url() . 'resource/imgbtn/delete_table.png" alt="Hapus Data" onclick = "dohapuscustomer(\'' . $row->idx . '\',\'' . substr($row->title, 0, 20) . '\');" style="border:none;">';
            $xbufResult .= tbaddrow(tbaddcell($row->idx) .
                    tbaddcell($row->title . ' ' . $row->firstname . ' ' . $row->midlename . ' ' . $row->lastname) .
                    tbaddcell($row->organization) .
                    tbaddcell($row->position) .
                    tbaddcell($row->address) .
                    tbaddcell($xButtonEdit . '&nbsp/&nbsp' . $xButtonHapus));
        }
        $xInput = form_input(getArrayObj('edSearch', '', '200'));
        $xButtonSearch = '<img src="' . base_url() . 'resource/imgbtn/b_view.png" alt="Search Data" onclick = "dosearchcustomer(0);" style="border:none;width:30px;height:30px;" />';
        $xButtonPrev = '<img src="' . base_url() . 'resource/imgbtn/b_prevpage.png" style="border:none;width:20px;" onclick = "dosearchcustomer(' . ($xAwal - $xLimit) . ');"/>';
        $xButtonNext = '<img src="' . base_url() . 'resource/imgbtn/b_nextpage.png" style="border:none;width:20px;" onclick = "dosearchcustomer(' . ($xAwal + $xLimit) . ');" />';
        $xbufResult .= tbaddrow(tbaddcell($xInput . $xButtonSearch, '', 'width=10% colspan=2') .
                tbaddcell($xButtonPrev . '&nbsp&nbsp' . $xButtonNext, '', 'width=40% colspan =10'), '', TRUE);
        $xbufResult = tablegrid($xbufResult);
        return '<div class="tabledata"  style="width:100%;left:-12px;">' . $xbufResult . '</div>';
    }

    function editreccustomer() {
        $xIdEdit = $_POST['edidx'];
        $this->load->model('modelcustomer');
        $row = $this->modelcustomer->getDetailcustomer($xIdEdit);
        $this->load->helper('json');
        $this->json_data['idx'] = $row->idx;
        $this->json_data['title'] = $row->title;
        $this->json_data['firstname'] = $row->firstname;
        $this->json_data['midlename'] = $row->midlename;
        $this->json_data['lastname'] = $row->lastname;
        $this->json_data['organization'] = $row->organization;
        $this->json_data['position'] = $row->position;
        $this->json_data['address'] = $row->address;
        $this->json_data['idcity'] = $row->idcity;
        $this->json_data['idstate'] = $row->idstate;
        $this->json_data['idcountry'] = $row->idcountry;
        $this->json_data['zipcode'] = $row->zipcode;
        $this->json_data['telepon'] = $row->telepon;
        $this->json_data['mobile'] = $row->mobile;
        $this->json_data['fax'] = $row->fax;
        $this->json_data['email'] = $row->email;
        $this->json_data['username'] = $row->username;
        $this->json_data['password'] = $row->password;
        $this->json_data['dateentry'] = $row->dateentry;
        $this->json_data['idpegawai'] = $row->idpegawai;
        $this->json_data['status'] = $row->status;
        echo json_encode($this->json_data);
    }

    function deletetablecustomer() {
        $edidx = $_POST['edidx'];
        $this->load->model('modelcustomer');
        $this->modelcustomer->setDeletecustomer($edidx);
        $this->load->helper('json');
        echo json_encode(null);
    }

    function searchcustomer() {
       // $xAwal = $_POST['xAwal'];
       // $xSearch = $_POST['xSearch'];
       $this->load->helper('json');
//        if (($xAwal + 0) == -99) {
//            $xAwal = $this->session->userdata('awal', $xAwal);
//        }
//        if ($xAwal + 0 <= -1) {
//            $xAwal = 0;
//            $this->session->set_userdata('awal', $xAwal);
//        } else {
//            $this->session->set_userdata('awal', $xAwal);
//        }
        $this->json_data['tabledatacustomer'] = $this->setDetailFormcustomer();
        echo json_encode($this->json_data);
    }

    function simpancustomer() {
        
        $this->load->helper('json');
        if (!empty($_POST['edcaptcha'])) {
            $captcha = $_POST['edcaptcha'];
        } else {
            $captcha = '0';
        }
        $xidx = '';
        $xxidx = $_POST['edidx'];
        $xtitle = $_POST['edtitle'];
        $xfirstname = $_POST['edfirstname'];
        $xmidlename = $_POST['edmidlename'];
        $xlastname = $_POST['edlastname'];
        $xorganization = $_POST['edorganization'];
        $xposition = $_POST['edposition'];
        $xaddress = $_POST['edaddress'];
        $xidcity = $_POST['edidcity'];
        $xidstate = $_POST['edidstate'];
        $xidcountry = $_POST['edidcountry'];
        $xzipcode = $_POST['edzipcode'];
        $xtelepon = $_POST['edtelepon'];
        $xmobile = $_POST['edmobile'];
        $xfax = $_POST['edfax'];
        $xemail = $_POST['edemail'];
        $xusername = $_POST['edusername'];
        $xpassword = $_POST['edpassword'];
        $xdateentry = $_POST['eddateentry'];
        $xidpegawai = $_POST['edidpegawai'];
        $xstatus = $_POST['edstatus'];
        $this->load->model('modelcustomer');
        $idpegawai = $this->session->userdata('idpegawai');
//        if (!empty($idpegawai)) {
           if ($captcha == '4') {
//                $xStr = $this->modelcustomer->setUpdatecustomer($xidx, $xtitle, $xfirstname, $xmidlename, $xlastname, $xorganization, $xposition, $xaddress, $xidcity, $xidstate, $xidcountry, $xzipcode, $xtelepon, $xmobile, $xfax, $xemail, $xusername, $xpassword, $xdateentry, $idpegawai, $xstatus);
//            } else {
                $xStr = $this->modelcustomer->setInsertcustomer($xidx, $xtitle, $xfirstname, $xmidlename, $xlastname, $xorganization, $xposition, $xaddress, $xidcity, $xidstate, $xidcountry, $xzipcode, $xtelepon, $xmobile, $xfax, $xemail, $xusername, $xpassword, $xdateentry, $idpegawai, $xstatus);
//            }
        }
        $this->load->model('modelcustomer');
        $rowakhir = $this->modelcustomer->getLastIndexcustomer();
        $this->json_data['captcha']= $captcha;
        $this->json_data['xxidx']=$rowakhir->idx;
        echo json_encode($this->json_data);
    }
    function pembayaran(){
        $edidcustomer = $_POST['edidx'];
        $this->load->helper('json');
        $this->load->helper('form');
        $xBufResult = '';
        $this->load->helper('common');
        $this->load->model('modelcustomer');
        $this->load->model('modelpaket');
        $row = $this->modelcustomer->getDetailcustomer($edidcustomer);
        $xBufResult .= '<input type="hidden" name="edidx" id="edidx" value="0" />';
        $xBufResult .= setForm('edidcustomer', 'Name ', form_input(getArrayObj('edidcustomer', $this->modelcustomer->getDetailnamacustomer($row->idx), '100'),'','disabled')) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edidpaket', 'Package', form_dropdown('edidcountry', $this->modelpaket->getArrayListpaket(), @$rowlast->idpaket, ' id="edidpaket_' . $row->idx . '" onChange="dosethargapaket(\'' . $row->idx . '\');" class="require" style="width:200px;" ')) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edjenisbayar', 'Bank Payment', form_textarea(getArrayObj('edjenisbayar_' . $row->idx, @$rowlast->jenisbayar, '300'))) . '<div class="spacer"></div>';
        $xBufResult .= setForm('edtotal', 'Total', form_input(getArrayObj('edtotal_' . $row->idx, '', '100'), '', 'disabled')) . '<div class="spacer"></div>';
    //    $xBufResult .= setForm('eddate_bayar', 'date_bayar', form_input(getArrayObj('eddate_bayar', '', '100'))) . '<div class="spacer"></div>';
    //    $xBufResult .= setForm('edidpegawai', 'idpegawai', form_input(getArrayObj('edidpegawai', '', '100'))) . '<div class="spacer"></div>';
        $xBufResult .= '<div class="garis"></div>' . form_button('btSimpan', 'Register', 'onclick="dosimpanhistoribayar(\''.$edidcustomer.'\');" class="textbtn base_btn pull-left" ') . /*form_button('btNew', 'new', 'onclick="doClearhistoribayar();"') .*/ '<div class="spacer"></div>';
        $this->json_data['formbayar'] =  $xBufResult;
        echo json_encode($this->json_data);
    }
    function simpanhistoribayar() {
        $this->load->helper('json');
        if (!empty($_POST['edidx'])) {
            $xidx = $_POST['edidx'];
        } else {
            $xidx = '0';
        }
        $this->load->helper('common');
        $xidcustomer = $_POST['edidcustomer'];
        $xidpaket = $_POST['edidpaket'];
        $xjenisbayar = $_POST['edjenisbayar'];
        $xtotal = $_POST['edtotal'];
        $xdate_bayar = ' ';
        $xidpegawai = $_POST['edidpegawai'];
        $xidstatusbayar = 'N';
        $this->load->model('modelhistoribayar');
        $idpegawai = $this->session->userdata('idpegawai');
        $this->json_data['href']= base_url();
        
       // if (!empty($idpegawai)) {
//            if ($xidx != '0') {
//                $xStr = $this->modelhistoribayar->setUpdatehistoribayar($xidx, $xidcustomer, $xidpaket, $xjenisbayar, $xtotal, date`$xdate_bayar, $xidpegawai);
//            } else {
            $xStr = $this->modelhistoribayar->setInserthistoribayarregister($xidx, $xidcustomer, $xidpaket, $xjenisbayar, $xtotal, $xdate_bayar, $xidstatusbayar,$idpegawai);
            //}
       // }
        echo json_encode($this->json_data);
    }

    ///////////////////////////////////
    function dosetstate() {
        $this->load->model('modelstate');
        $xidcountry = $_POST['xidcountry'];
        $this->load->helper('json');
        $this->json_data['optionstate'] = $this->modelstate->getoptionstatebycountry($xidcountry);
        echo json_encode($this->json_data);
    }

    function dosetcity() {
        $this->load->model('modelcity');
        $xidstate = $_POST['xidstate'];
        $this->load->helper('json');
        $this->json_data['optioncity'] = $this->modelcity->getoptionstatebyidstate($xidstate);
        echo json_encode($this->json_data);
    }

}

?>